Modify Enum from Trigger

I have a function to modify an enumerated attribute type and I am 100% sure that this function works. It is similar to what I posted here, http://www.ibm.com/developerworks/forums/thread.jspa?threadID=379624&tstart=0. I have an attribute that is a multi valued enum - one that people who hate/are afraid of doors will have to edit and possibly add a new value to. I added the value "Add New" to this OE and have written a trigger to execute when "Add New" is selected for this attribute. The trigger opens a simple DB where they can enter the text and select another option or two, then add the new value to the enum. The modify command - shown in the referenced thread - is causing an exception access violation and I can not figure out why for the life me. The only difference between the error version and a version that works fine is that this one is written in a string so I escaped all quotes and such. My first thought was that since the trigger is caused by the attribute, it may not be possible to edit the type - but I don't think that is so because I changed the code to change the attribute's value and there were no issues with that. I am 99% sure that I am not getting the wrong type from the Skip or leaving anything undeleted or anything like that. Any ideas? Here is a snippet of the code which is embedded in a string.

{code}
void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}

Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i

// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}

// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation

delete(enumVals)
delete(aModify)
}
SystemAdmin - Tue Aug 09 18:20:56 EDT 2011

Re: Modify Enum from Trigger
SystemAdmin - Tue Aug 09 18:21:46 EDT 2011

here is the code again,


void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}

Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i

// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}

// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation

delete(enumVals)
delete(aModify)
}

{code}

Re: Modify Enum from Trigger
SystemAdmin - Tue Aug 09 18:22:52 EDT 2011

SystemAdmin - Tue Aug 09 18:21:46 EDT 2011
here is the code again,


void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}

Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i

// first, put the existing enum values into the skip
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}

// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation

delete(enumVals)
delete(aModify)
}

{code}

it has been a horribly long day, sorry
 

void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
 
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
 
// first, put the existing enum values into the skip 
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
 
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
 
delete(enumVals)
delete(aModify)
}

Re: Modify Enum from Trigger
llandale - Wed Aug 10 09:55:47 EDT 2011

SystemAdmin - Tue Aug 09 18:22:52 EDT 2011

it has been a horribly long day, sorry
 

void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
 
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
 
// first, put the existing enum values into the skip 
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
 
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
 
delete(enumVals)
delete(aModify)
}

I'm guessing that you cannot modify the "type" of an attribute WHILE you are also modifying the value of it. Exaggeration: how would DOORS handle an "Add New" modification to the value if the trigger removed "Add New" from the list?

Not sure what to suggest so I'll babble:
[] have some other simple attribute with "Add New" that applies to your main attr's enum list.
[] I wonder if you cancel the in-place editing before modifying you may have better luck
... bool inplaceEditOff(Module,bool) // Abort. bool parameter does something??
[] I wonder if this attr-trigger could set the dummy value of some other attr that also has the trigger, this one fails, and the other trigger does your work to modify this list.
[] Try post -save-attr trigger that sees if "Add New" is one of the current values.

Nit-Picks: I really don't see how your code could work but perhaps I'm missing something.
[] I see that you insist on sorting the Enums alphabetically because the string value is the KEY to your skip. If you made "i" the KEY you would preserve the original order. But what you have seems to work if it starts sorted and you want to keep it sorted.
[] Your Mapping part needs fixed. If you insert "B" between existing "A"(#0) and "C"(#1), the yes the "B" mapping #1 = -1, but the "C" mapping #2 should be = 1, its original position. My first guess is change...
from ... put(aModify, j, j, 3)
to ....... put(aModify, k++, j, 3)
setting k=0 before the loop.

  • Louie

Re: Modify Enum from Trigger
Mathias Mamsch - Wed Aug 10 10:57:23 EDT 2011

SystemAdmin - Tue Aug 09 18:22:52 EDT 2011

it has been a horribly long day, sorry
 

void addtoEnum(string enumName, string newVal, bool isOptional){
current = mod
AttrType at = find(mod, enumName)
if (null at){
errorBox(enumName \" not found\")
return
}
 
Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
int i
 
// first, put the existing enum values into the skip 
for (i = 0; i < at.size; i++){
if (at.strings[i] != \"Add New\"){
put(enumVals, at.strings[i], i\"\")
}
}
 
// put the new value into the skip
put(enumVals, newVal, i\"\")
// modify the enumeration
Array aModify = create(at.size + 1, 4) // (*,0) contains strings
// (*,1) contains associated index
// (*,2) contains color value, -1 = don't care
// (*,3) contains mapping
string temp, insVal, errMsg = null
int j = 1
// put sorted skip vals into array
put(aModify, \"Add New\", 0 , 0)
put(aModify, 0, 0, 1)
put(aModify, -1, 0, 2)
put(aModify, -1, 0, 3)
for temp in enumVals do {
insVal = (string key(enumVals))
put(aModify, insVal, j, 0)
put(aModify, j, j, 1)
put(aModify, -1, j, 2)
if (insVal == newVal){
put(aModify, -1, j, 3)
} else {
put(aModify, j, j, 3)
}
j++
}
// modify the type and delete the array
at = modify(at, enumName, aModify, errMsg) // this line causes exception access violation
 
delete(enumVals)
delete(aModify)
}

Hey Adam,

if you say for yourself, that the only difference between the working and non-working versions is only that one of them is written "in a string", it sounds reasonable, that you do something very naughty outside the code you posted, that will make the code crash once you call it.

Are you maybe using eval_ to execute that code? There are a lot of pitfalls with eval_ so maybe can you tell us, how you call the code from the string?

Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Modify Enum from Trigger
SystemAdmin - Wed Aug 10 11:38:05 EDT 2011

Mathias Mamsch - Wed Aug 10 10:57:23 EDT 2011
Hey Adam,

if you say for yourself, that the only difference between the working and non-working versions is only that one of them is written "in a string", it sounds reasonable, that you do something very naughty outside the code you posted, that will make the code crash once you call it.

Are you maybe using eval_ to execute that code? There are a lot of pitfalls with eval_ so maybe can you tell us, how you call the code from the string?

Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

The code is called from a trigger. I have a string variable, DXLCode, that contains the code that executes. The trigger is a post modify on the attribute. When the attribute is changed, I check to see if "Add New" has been selected in the multi-valued enum. If it has been I want to open a dialog box from which the user can just type in the new value they wish to add, and add it to the enum from there. Everything seems to be working just fine, except for the actualy modify command.

Re: Modify Enum from Trigger
SystemAdmin - Wed Aug 10 11:46:24 EDT 2011

llandale - Wed Aug 10 09:55:47 EDT 2011
I'm guessing that you cannot modify the "type" of an attribute WHILE you are also modifying the value of it. Exaggeration: how would DOORS handle an "Add New" modification to the value if the trigger removed "Add New" from the list?

Not sure what to suggest so I'll babble:
[] have some other simple attribute with "Add New" that applies to your main attr's enum list.
[] I wonder if you cancel the in-place editing before modifying you may have better luck
... bool inplaceEditOff(Module,bool) // Abort. bool parameter does something??
[] I wonder if this attr-trigger could set the dummy value of some other attr that also has the trigger, this one fails, and the other trigger does your work to modify this list.
[] Try post -save-attr trigger that sees if "Add New" is one of the current values.

Nit-Picks: I really don't see how your code could work but perhaps I'm missing something.
[] I see that you insist on sorting the Enums alphabetically because the string value is the KEY to your skip. If you made "i" the KEY you would preserve the original order. But what you have seems to work if it starts sorted and you want to keep it sorted.
[] Your Mapping part needs fixed. If you insert "B" between existing "A"(#0) and "C"(#1), the yes the "B" mapping #1 = -1, but the "C" mapping #2 should be = 1, its original position. My first guess is change...
from ... put(aModify, j, j, 3)
to ....... put(aModify, k++, j, 3)
setting k=0 before the loop.

  • Louie

@Louie, do you think that issue with my array mapping could cause the exception access violation? To be honest, I have never paid too much attention to it - as long as the right values have been showing up in the drop down I haven't given it any second thought.

Re: Modify Enum from Trigger
llandale - Wed Aug 10 15:17:38 EDT 2011

SystemAdmin - Wed Aug 10 11:38:05 EDT 2011
The code is called from a trigger. I have a string variable, DXLCode, that contains the code that executes. The trigger is a post modify on the attribute. When the attribute is changed, I check to see if "Add New" has been selected in the multi-valued enum. If it has been I want to open a dialog box from which the user can just type in the new value they wish to add, and add it to the enum from there. Everything seems to be working just fine, except for the actualy modify command.

So you have 5 previous enums numbered #0-#4 and you add a new one in the middle for now 6 numbered #0-#5. The last enum in your Array #5 will have a mapping to previous enum also #5; but there is no such previous Enum. I suppose that could cause an exception. Try my "k++" solution which will result in #5 (the new last one) mapping to #4 (the previous last one).

Position:   0 1 2 3 4
Old Enums:  A B D E
New Enums:  A B C D E  // inserting "C"
Map Needed: 0 1 - 2 3
Map Actual: 0 1 - 3 4  // your algorithm

 


If this is a "post" then the attr is already updated and you should then de-select that enum; I think:
obj.NameAttr -= "Add New"
Otherwise the next time they modify the value, innocently not noticing that "Add New" is still selected, your trigger will fire as will their tempers.

 

 

 

  • Louie

 

 

Re: Modify Enum from Trigger
SystemAdmin - Wed Aug 10 15:40:31 EDT 2011

llandale - Wed Aug 10 15:17:38 EDT 2011

So you have 5 previous enums numbered #0-#4 and you add a new one in the middle for now 6 numbered #0-#5. The last enum in your Array #5 will have a mapping to previous enum also #5; but there is no such previous Enum. I suppose that could cause an exception. Try my "k++" solution which will result in #5 (the new last one) mapping to #4 (the previous last one).

Position:   0 1 2 3 4
Old Enums:  A B D E
New Enums:  A B C D E  // inserting "C"
Map Needed: 0 1 - 2 3
Map Actual: 0 1 - 3 4  // your algorithm

 


If this is a "post" then the attr is already updated and you should then de-select that enum; I think:
obj.NameAttr -= "Add New"
Otherwise the next time they modify the value, innocently not noticing that "Add New" is still selected, your trigger will fire as will their tempers.

 

 

 

  • Louie

 

 

I tried the k++ solution and I'm getting the same issue. And I do deselect the "Add New" after the modify command, I also am trying to assign the new value at that point to but I cant assign it yet because the modify isn't working.

Here is my current code for building the modification array
 

int j = 1, k = 0
        // put sorted skip vals into array, keep "Add New" at the top
                put(aModify, \"Add New\", 0 , 0)
                put(aModify, 0, 0, 1)
                put(aModify, -1, 0, 2)
                put(aModify, 0, 0, 3)
                for temp in enumVals do {
                        insVal = (string key(enumVals))
                        put(aModify, insVal, j, 0)
                        put(aModify, j, j, 1)
                        put(aModify, -1, j, 2)
                        if (insVal == newVal){
                                put(aModify, -1, j, 3)
                        } else {
                                put(aModify, k++, j, 3) // as per louie's suggestion
                        }
                        j++
                }
                // modify the type and delete the array
                at = modify(at, enumName, aModify, errMsg)
 
                delete(enumVals)
                delete(aModify)

Re: Modify Enum from Trigger
llandale - Wed Aug 10 17:55:25 EDT 2011

SystemAdmin - Wed Aug 10 15:40:31 EDT 2011

I tried the k++ solution and I'm getting the same issue. And I do deselect the "Add New" after the modify command, I also am trying to assign the new value at that point to but I cant assign it yet because the modify isn't working.

Here is my current code for building the modification array
 

int j = 1, k = 0
        // put sorted skip vals into array, keep "Add New" at the top
                put(aModify, \"Add New\", 0 , 0)
                put(aModify, 0, 0, 1)
                put(aModify, -1, 0, 2)
                put(aModify, 0, 0, 3)
                for temp in enumVals do {
                        insVal = (string key(enumVals))
                        put(aModify, insVal, j, 0)
                        put(aModify, j, j, 1)
                        put(aModify, -1, j, 2)
                        if (insVal == newVal){
                                put(aModify, -1, j, 3)
                        } else {
                                put(aModify, k++, j, 3) // as per louie's suggestion
                        }
                        j++
                }
                // modify the type and delete the array
                at = modify(at, enumName, aModify, errMsg)
 
                delete(enumVals)
                delete(aModify)

Tweaked the code a lot, added prints, but I think the only real change was inconsequencial from "k = 0" to "k = 1". It works the first time but I get exception violations the 2nd time when inserting an Enum that is already there. So your dialog must make sure the "enumName" doesn't already exist (or this code does nothing if it already does).

  • Louie

Re: Modify Enum from Trigger
SystemAdmin - Wed Aug 10 18:29:56 EDT 2011

llandale - Wed Aug 10 17:55:25 EDT 2011
Tweaked the code a lot, added prints, but I think the only real change was inconsequencial from "k = 0" to "k = 1". It works the first time but I get exception violations the 2nd time when inserting an Enum that is already there. So your dialog must make sure the "enumName" doesn't already exist (or this code does nothing if it already does).

  • Louie

Would you mind posting the code? I thought that using the enum values as the key in the skip list would prevent duplicates, is this not correct? Thanks for all your help!

-Adam

Re: Modify Enum from Trigger
llandale - Thu Aug 11 10:34:23 EDT 2011

SystemAdmin - Wed Aug 10 18:29:56 EDT 2011
Would you mind posting the code? I thought that using the enum values as the key in the skip list would prevent duplicates, is this not correct? Thanks for all your help!

-Adam

It does prevent duplicates in the Skip, but you are still commanding a change to the Type with enumerations that are the same and mapping that is not, and for some reason it cannot handle it. Your mapping algorithm, especially when I changed it to k++, presumes the New Value was NOT already defined and is INSERTING, moving the other's down.

Don't be offended I was playful with a couple of the variable names.
This code was put in a file:

Module mod = current()
void addtoEnum(string enumName, string newVal, bool isOptional)
{
    current = mod
        AttrType at = find(mod, enumName)
        if (null at)
        {  errorBox(enumName " not found")
           return
        }
 
        Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
        int i
 
                // first, put the existing enum values into the skip 
        for (i = 0; i < at.size; i++)
        {  if (at.strings[i] != "Add New")
           {  put(enumVals, at.strings[i], i "")
           }
        }
 
                // put the new value into the skip
        put(enumVals, newVal, i "")
                // modify the enumeration
        Array aModify = create(at.size + 1, 4) // (*,0) contains strings
                // (*,1) contains associated index
                // (*,2) contains color value, -1 = don't care
                // (*,3) contains mapping
        string temp, insVal, errMsg = null
 
 
 
        int j = 1, k = 1                        // K=1
                // put sorted skip vals into array, keep "Add New" at the top
        put(aModify,   "Add New", 0, 0)
        put(aModify,           0, 0, 1)
        put(aModify,          -1, 0, 2)
        put(aModify,           0, 0, 3)                 //      put(aModify, -1, 0, 3)
        for temp in enumVals do 
        {  insVal = (string key(enumVals))
           put(aModify,  insVal,  j, 0)
           put(aModify,       j,  j, 1)
           put(aModify,      -1,  j, 2)
           if (insVal == newVal)        //
           then put(aModify, -1,  j, 3)
           else put(aModify, k++, j, 3) // as per louie's suggestion
           j++
        }
                // modify the type and delete the array
 
        print "i\tSkipEnum\t----------\n"
        for temp in enumVals do
        {  insVal = (string key enumVals)
           print temp "\t" insVal "\n"
        }
 
        print "i\tName.. \tNum\tColor\tMap\t----------\n"
        for (i=0; i<j; i++)
        {  print i   "\t" (string get(aModify, i, 0)) //
                        "\t" (int    get(aModify, i, 1)) //
                        "\t" (int    get(aModify, i, 2)) //
                        "\t" (int    get(aModify, i, 3)) //
                        "\n"
        }
 
        at = modify(at, enumName, aModify, errMsg)
 
        delete(enumVals)
        delete(aModify)
}    // end addtoEnum()
 
addtoEnum("aPrulhiere_Fiasco", "CCCCCC", true)


This code was used to deploy the above code:

 

// #include <InProgress\Temp2.dxl>
Module mod = current
 
string DXLCode = readFile("c:/Doors-Stuff/DXL-Local/InProgress/Temp2.dxl")
string NameTrig = "Prulhiere_Fiasco"
string NameAttr  = "aPrulhiere_Fiasco"
Trigger trg
for trg in mod do
{  if (name(trg) == NameTrig)
   {  delete(trg)
      break
   }
}
if (!confirm("Deploy Trig??")) halt
trg = trigger(NameTrig, module->attribute, post, save, 5, DXLCode)


No doubt you would escape the slashes and quotes in the first "file" and insert it hard coded where the 2nd code does the "readFile".

 

Re: Modify Enum from Trigger
SystemAdmin - Fri Aug 12 15:14:43 EDT 2011

llandale - Thu Aug 11 10:34:23 EDT 2011

It does prevent duplicates in the Skip, but you are still commanding a change to the Type with enumerations that are the same and mapping that is not, and for some reason it cannot handle it. Your mapping algorithm, especially when I changed it to k++, presumes the New Value was NOT already defined and is INSERTING, moving the other's down.

Don't be offended I was playful with a couple of the variable names.
This code was put in a file:

Module mod = current()
void addtoEnum(string enumName, string newVal, bool isOptional)
{
    current = mod
        AttrType at = find(mod, enumName)
        if (null at)
        {  errorBox(enumName " not found")
           return
        }
 
        Skip enumVals = createString() // KEY: string (OE name); DATA: string - irrelevant
        int i
 
                // first, put the existing enum values into the skip 
        for (i = 0; i < at.size; i++)
        {  if (at.strings[i] != "Add New")
           {  put(enumVals, at.strings[i], i "")
           }
        }
 
                // put the new value into the skip
        put(enumVals, newVal, i "")
                // modify the enumeration
        Array aModify = create(at.size + 1, 4) // (*,0) contains strings
                // (*,1) contains associated index
                // (*,2) contains color value, -1 = don't care
                // (*,3) contains mapping
        string temp, insVal, errMsg = null
 
 
 
        int j = 1, k = 1                        // K=1
                // put sorted skip vals into array, keep "Add New" at the top
        put(aModify,   "Add New", 0, 0)
        put(aModify,           0, 0, 1)
        put(aModify,          -1, 0, 2)
        put(aModify,           0, 0, 3)                 //      put(aModify, -1, 0, 3)
        for temp in enumVals do 
        {  insVal = (string key(enumVals))
           put(aModify,  insVal,  j, 0)
           put(aModify,       j,  j, 1)
           put(aModify,      -1,  j, 2)
           if (insVal == newVal)        //
           then put(aModify, -1,  j, 3)
           else put(aModify, k++, j, 3) // as per louie's suggestion
           j++
        }
                // modify the type and delete the array
 
        print "i\tSkipEnum\t----------\n"
        for temp in enumVals do
        {  insVal = (string key enumVals)
           print temp "\t" insVal "\n"
        }
 
        print "i\tName.. \tNum\tColor\tMap\t----------\n"
        for (i=0; i<j; i++)
        {  print i   "\t" (string get(aModify, i, 0)) //
                        "\t" (int    get(aModify, i, 1)) //
                        "\t" (int    get(aModify, i, 2)) //
                        "\t" (int    get(aModify, i, 3)) //
                        "\n"
        }
 
        at = modify(at, enumName, aModify, errMsg)
 
        delete(enumVals)
        delete(aModify)
}    // end addtoEnum()
 
addtoEnum("aPrulhiere_Fiasco", "CCCCCC", true)


This code was used to deploy the above code:

 

// #include <InProgress\Temp2.dxl>
Module mod = current
 
string DXLCode = readFile("c:/Doors-Stuff/DXL-Local/InProgress/Temp2.dxl")
string NameTrig = "Prulhiere_Fiasco"
string NameAttr  = "aPrulhiere_Fiasco"
Trigger trg
for trg in mod do
{  if (name(trg) == NameTrig)
   {  delete(trg)
      break
   }
}
if (!confirm("Deploy Trig??")) halt
trg = trigger(NameTrig, module->attribute, post, save, 5, DXLCode)


No doubt you would escape the slashes and quotes in the first "file" and insert it hard coded where the 2nd code does the "readFile".

 

HAHA, I like the new variable names - they are definitely more accurate than what I had.

I am still getting the exception access violation though. Now it says that the error is caused by "delete(aModify)" but I don't think it's right. I commented some lines out and it looks like it's still the "at = modify..." that is causing there error. But now when it happens it only says 38% of memory is in use where as before it was anywhere from 54-62%.

-Adam

Re: Modify Enum from Trigger
llandale - Sun Aug 14 23:45:44 EDT 2011

SystemAdmin - Fri Aug 12 15:14:43 EDT 2011
HAHA, I like the new variable names - they are definitely more accurate than what I had.

I am still getting the exception access violation though. Now it says that the error is caused by "delete(aModify)" but I don't think it's right. I commented some lines out and it looks like it's still the "at = modify..." that is causing there error. But now when it happens it only says 38% of memory is in use where as before it was anywhere from 54-62%.

-Adam

You get the exception the first time you insert a new Enum?

You could start with my code and slowly make it look like your code, running it frequently, until you get your exception.

  • Louie

Re: Modify Enum from Trigger
SystemAdmin - Mon Aug 15 10:31:41 EDT 2011

llandale - Sun Aug 14 23:45:44 EDT 2011
You get the exception the first time you insert a new Enum?

You could start with my code and slowly make it look like your code, running it frequently, until you get your exception.

  • Louie

Yeah I get it the first time. I'll take some time and rework the whole thing when I have some time. Thanks again for your help.

-Adam

Re: Modify Enum from Trigger
SystemAdmin - Mon Aug 15 11:05:23 EDT 2011

SystemAdmin - Mon Aug 15 10:31:41 EDT 2011
Yeah I get it the first time. I'll take some time and rework the whole thing when I have some time. Thanks again for your help.

-Adam

I started with your code exactly as is - a few minor changes in variables names but no functional changes - and I get the access violation on the first execution.

Re: Modify Enum from Trigger
llandale - Mon Aug 15 11:52:11 EDT 2011

SystemAdmin - Mon Aug 15 11:05:23 EDT 2011
I started with your code exactly as is - a few minor changes in variables names but no functional changes - and I get the access violation on the first execution.

You see nothing wrong looking at the print statements from my code?

Delete the existing "int i" and add this at the top, before your Skip statement:

int i
        // Check for existing value
        for (i = 0; i < at.size; i++)
        {  if (at.strings[i] != newVal
           {  errorBox("New value already exists: '" newVal "'")
              return
           }
        }   // end check for existing value

 

  • Louie

 

Re: Modify Enum from Trigger
SystemAdmin - Mon Aug 15 11:58:11 EDT 2011

llandale - Mon Aug 15 11:52:11 EDT 2011

You see nothing wrong looking at the print statements from my code?

Delete the existing "int i" and add this at the top, before your Skip statement:

int i
        // Check for existing value
        for (i = 0; i < at.size; i++)
        {  if (at.strings[i] != newVal
           {  errorBox("New value already exists: '" newVal "'")
              return
           }
        }   // end check for existing value

 

  • Louie

 

That is causing the errorBox to show saying that the new value already exists, but I don't see the new value in the drop down.

Re: Modify Enum from Trigger
SystemAdmin - Mon Aug 15 12:33:29 EDT 2011

SystemAdmin - Mon Aug 15 11:58:11 EDT 2011
That is causing the errorBox to show saying that the new value already exists, but I don't see the new value in the drop down.

I didnt really have time to look at that before - just did a copy paste and run - but now that I look at it, it is throwing the errorBox when at.strings[i] is not equal to newVal so really the issue isn't that the value already exists in the enum. I'll take a closer look at the print statements output for the new mapping of the enum.

Re: Modify Enum from Trigger
SystemAdmin - Mon Aug 15 14:20:33 EDT 2011

SystemAdmin - Mon Aug 15 12:33:29 EDT 2011
I didnt really have time to look at that before - just did a copy paste and run - but now that I look at it, it is throwing the errorBox when at.strings[i] is not equal to newVal so really the issue isn't that the value already exists in the enum. I'll take a closer look at the print statements output for the new mapping of the enum.

I finally figured it out! It was an issue with the mapping and new value addition like you suggested earlier. Here is the final version that is working correctly.
 

AttrType at = find(mod, adType)
                        if (null at){
                                        errorBox(\"Type Not Found\")
                                        halt()
                                }
                                
                                Array aModify = create(at.size + 1, 4)
                                Skip enumVals = createString()  // KEY: string - new OE; DATA: int - mapping value
                                
                                int i
                                for (i = 0; i < at.size; i++){
                                        if (at.strings[i] != \"New OE\"){
                                                put(enumVals, at.strings[i], i)
                                        }
                                }
                                string newVal = (string get(newOEtext))
                                put(enumVals, newVal, -1)
                
                                put(aModify, \"New OE\", 0, 0)
                                put(aModify, 0, 0, 1)
                                put(aModify, -1, 0, 2)
                                put(aModify, 0, 0, 3)                           
 
 
                                int temp, j = 1
                                string eVal, errorMsg = \"\"
                                for temp in enumVals do {
                                        eVal = (string key(enumVals))
                                        put(aModify, eVal, j, 0)
                                        put(aModify, j, j, 1)
                                        put(aModify, -1, j, 2)
                                        put(aModify, temp, j, 3)
                                        j++ 
                                }
                                
                                at = modify(at, adType, aModify, errorMsg)
 
                                delete(enumVals)
                                delete(aModify)

Re: Modify Enum from Trigger
llandale - Mon Aug 15 17:58:56 EDT 2011

SystemAdmin - Mon Aug 15 11:58:11 EDT 2011
That is causing the errorBox to show saying that the new value already exists, but I don't see the new value in the drop down.

Sorry, if they are equal:
{ if (at.strings[i] == newVal)

Re: Modify Enum from Trigger
SystemAdmin - Wed Aug 17 15:22:49 EDT 2011

llandale - Mon Aug 15 17:58:56 EDT 2011
Sorry, if they are equal:
{ if (at.strings[i] == newVal)

I am trying to do something very similar with a post open trigger on the module. When the module is opened I want to update an enum to contain certain options depending on their status in another module. The modify command returns "Module not open for edit." even though I am opening in exclusive edit. The trigger will update an attribute no problem so it's definitely opened for edit. Any thoughts?

-Adam

Re: Modify Enum from Trigger
llandale - Thu Aug 18 15:55:48 EDT 2011

SystemAdmin - Wed Aug 17 15:22:49 EDT 2011
I am trying to do something very similar with a post open trigger on the module. When the module is opened I want to update an enum to contain certain options depending on their status in another module. The modify command returns "Module not open for edit." even though I am opening in exclusive edit. The trigger will update an attribute no problem so it's definitely opened for edit. Any thoughts?

-Adam

This is no-doubt a "current module" problem. Some commands including the "modify" presume the current module. In your case it seems that the current module is changing to the other module after you open it. Thus, your "modify" command is being applied to the other module which is not open for Edit.

In any case, these commands that presume the current module 'should', in my opinion, always be preceded with setting that current module right before its needed. The generic code looks like this:

Module mod = module(trg)
...
Module mCurr = current     // Remember which one is currently Current
current = mod              // set this one current
deal with modify et tal
if (!null mCurr) current = mCurr  // Re-instate the previous Current


You usually do not need "mCurr" but it will re-instate the current module in case some other piece of code is presuming it.

So when the DXL manual says the command works on the "current module" you know what to do.

 

 

  • Louie


It gives me the HeeBeeGeeBees to see you wanting to modify Enum values whenever the module is opened Edit. Triggers and auto-updates are dangerous. I think you should take a step back and figure out what you are really doing. Are you SURE you are going to map the old values to the new ones correctly each time; and are you SURE you want these things at the mercy of some other dude in some other module?

 

 

Re: Modify Enum from Trigger
SystemAdmin - Fri Aug 19 10:39:49 EDT 2011

llandale - Thu Aug 18 15:55:48 EDT 2011

This is no-doubt a "current module" problem. Some commands including the "modify" presume the current module. In your case it seems that the current module is changing to the other module after you open it. Thus, your "modify" command is being applied to the other module which is not open for Edit.

In any case, these commands that presume the current module 'should', in my opinion, always be preceded with setting that current module right before its needed. The generic code looks like this:

Module mod = module(trg)
...
Module mCurr = current     // Remember which one is currently Current
current = mod              // set this one current
deal with modify et tal
if (!null mCurr) current = mCurr  // Re-instate the previous Current


You usually do not need "mCurr" but it will re-instate the current module in case some other piece of code is presuming it.

So when the DXL manual says the command works on the "current module" you know what to do.

 

 

  • Louie


It gives me the HeeBeeGeeBees to see you wanting to modify Enum values whenever the module is opened Edit. Triggers and auto-updates are dangerous. I think you should take a step back and figure out what you are really doing. Are you SURE you are going to map the old values to the new ones correctly each time; and are you SURE you want these things at the mercy of some other dude in some other module?

 

 

I was personally against this function but hey, I do what they tell me to do. The whole point of this is to restrict the choices people can make in a certain module - rather than checking and denying the change when an invalid choice is selected they want to display only valid options. Luckily the module that is used to determine the validity is locked down and only the admins can make changes in it. And due to recent changes in the design it looks like we wont being doing it this way afterall so I am a bit relieved. Thanks for the input, as always, it was very helpful.

-Adam